package com.lovenote.common.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.base.common.dao.IBaseDao;
import com.base.common.service.impl.BaseServiceImpl;
import com.lovenote.common.dao.INoteCatalogDao;
import com.lovenote.common.pojo.NoteCatalog;
import com.lovenote.common.service.INoteCatalogService;

@Service("noteCatalogService")
public class NoteCatalogServiceImpl extends BaseServiceImpl<NoteCatalog, Integer> implements INoteCatalogService {

	private INoteCatalogDao noteCatalogDao;
	
	@Autowired
	@Qualifier("noteCatalogDao")
	@Override
	public void setBaseDao(IBaseDao<NoteCatalog, Integer> baseDao) {
		this.baseDao = baseDao;
		this.noteCatalogDao = (INoteCatalogDao) baseDao;
	}

	@Override
	public boolean isNameUnique(long userId, String name) {
		String[] keys = {"userId", "name"};
		Object[] values = {userId, name};
		List<NoteCatalog> noteCatalogs = this.noteCatalogDao.loadByProperties(keys, values);
		if (noteCatalogs.size() > 0) {
			return true;
		}
		return false;
	}

	@Override
	public List<NoteCatalog> getNoteCatalogList(long userId) {
		return this.noteCatalogDao.loadByProperty("userId", userId, "orderId", "asc");
	}

	@Override
	public boolean deleteCatalog(long userId, int catalogId) {
		return this.noteCatalogDao.deleteCatalog(userId, catalogId);
	}
	

}
